
<%@page import="fu.abc.DAO.CategoryDAO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="fu.abc.model.Category"%>
<%@page import="java.util.List"%>
<%@page import="fu.abc.model.Location"%>
<%@page import="fu.abc.DAO.LocationDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/additional-methods.min.js"></script>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Vnplace - Quản lý địa điểm</title>
	
	<!-- CSS -->
	<link href="css/transcreate.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="css/editlocal.css" rel="stylesheet" type="text/css" media="screen" />
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
	<script src='jquery.js' type='text/javascript'></script>
	
	<style>
		body {
			font-size: 15px;
		}
		#header {
			height: 60px;
			width: max;
			background: #19A3A3;
			color: white;
		}
		ul#header-menu li{
			float: left;
			margin-top: 20px;
			
		}
		p.logo{
			margin-left: 45px;
			font-size: 1.2em;
			border-right: 1px solid #8F939E;
		}
		
		a.logout {
			list-style: none;
			font-size: 15px;
			margin-left: 20px;
			color: white;
		}
		
		a.logout:hover {
			color: #E6E6B8;
			text-decoration: underline;
		}
		
		p.hello {
			margin-left: 970px;
		}
		
		a.name {
			text-decoration: none;
		}
		
		a.name:hover {
			text-decoration: underline;
			color: black;
		}
		li.create{
			background: #CCEBEB;
		}
		ul.ul-sort li{
			float: left;
		}
		input.sort{
			height: 26px;
			width: 60px;
			margin-left: 3px;
			margin-bottom: 10px;
			
		}
		
		#page_navigation a{
			margin-top: 30px;
		    padding:3px;
		    border:1px solid gray;
		    margin: 3px;
		    color:black;
		    text-decoration:none
		}
		#page_navigation a:hover{background:#ccc;}
		.active_page{
		    background:#555;
		    color:red !important;
		}
		hr{
			background: gray;
		}
		#districts{
			width: 150px;
			margin-bottom: 10px;
		}
					span
			{
    		font-weight:inherit;
			}
	</style>
	<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
	<script>
		function initialize() {
			  var mapOptions = {
			    center: new google.maps.LatLng(15.9030623,105.8066925),
			    zoom: 13
			  };
			  var map = new google.maps.Map(document.getElementById('map-canvas'),
			    mapOptions);
	
			  var input = (document.getElementById('district'));
// 			  map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
			  var autocomplete = new google.maps.places.Autocomplete(input);
			  autocomplete.bindTo('bounds', map);
	
			  var infowindow = new google.maps.InfoWindow();
			  var marker = new google.maps.Marker({
			    map: map,
			    anchorPoint: new google.maps.Point(0, -29)
			  });
	
			  google.maps.event.addListener(autocomplete, 'place_changed', function() {
			    infowindow.close();
			    marker.setVisible(false);
			    var place = autocomplete.getPlace();
			    if (!place.geometry) {
			      return;
			    }
	
			    // If the place has a geometry, then present it on a map.
			    if (place.geometry.viewport) {
			      map.fitBounds(place.geometry.viewport);
			    } else {
			      map.setCenter(place.geometry.location);
			      map.setZoom(17);  // Why 17? Because it looks good.
			    }
			    /** @type {google.maps.Icon} */
			    marker.setIcon(({
			      url: place.icon,
			      size: new google.maps.Size(71, 71),
			      origin: new google.maps.Point(0, 0),
			      anchor: new google.maps.Point(17, 34),
			      scaledSize: new google.maps.Size(35, 35)
			    }));
			    marker.setPosition(place.geometry.location);
			    marker.setVisible(true);
	
// 			    var address = '';
// 			    if (place.address_components) {
// 			      address = [
// 			        (place.address_components[0] && place.address_components[0].short_name || ''),
// 			        (place.address_components[1] && place.address_components[1].short_name || ''),
// 			        (place.address_components[2] && place.address_components[2].short_name || '')
// 			      ].join(' ');
// 			    }
			  });
	
			  // Sets a listener on a radio button to change the filter type on Places
			  // Autocomplete.
			}
	
		google.maps.event.addDomListener(window, 'load', initialize);
	</script>
	<!-- star validate phone -->
		
		<script type="text/javascript">
			$(document).ready(function() {
			    $('#txtPhone').blur(function(e) {
			        if (validatePhone('txtPhone')) {
			            $('#spnPhoneStatus').html(' ');
			            $('#spnPhoneStatus').css('color', 'green');
			        }
			        else {
			            $('#spnPhoneStatus').html(' Độ dài từ 8 đến 11 số ');
			            $('#spnPhoneStatus').css('color', 'red');
			        }
			    });
			});
			$(document).ready(function() {
			    $('#txtWebsite').blur(function(e) {
			        if (validateWeb('txtWebsite')) {
			            $('#spnWebStatus').html(' ');
			            $('#spnWebStatus').css('color', 'green');
			        }
			        else {
			            $('#spnWebStatus').html(' Không hợp lệ ');
			            $('#spnWebStatus').css('color', 'red');
			        }
			    });
			});
			
			function validatePhone(txtPhone) {
			    var a = document.getElementById(txtPhone).value;
			    var filter = /0\d{9,10}/;
			    if (filter.test(a)) {
			        return true;
			    }
			    else {
			        return false;
			    }
			}
			function validateWeb(txtWebsite) {
			    var a = document.getElementById(txtWebsite).value;
			    var filter = /^([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
			    if (filter.test(a)) {
			        return true;
			    }
			    else {
			        return false;
			    }
			}
			</script>
<!-- End validate phone		 -->
	
</head>

<body class="dt-example">
	<div id="wrapper">
		<!-- h1 tag stays for the logo, you can use the a tag for linking the index page -->
		<div id="header">
		<%String acc = (String)session.getAttribute("acc"); %>
		<ul id="header-menu">
			<li><p class="logo">Content-Editor</p></li>
			<li>
			<%

				if(acc==null){
					response.sendRedirect("/Vnplace/systemAdmin/login.jsp");
				}else{
				
 			%>
				<p class="hello">
					Chào <b><%=acc %></b>
				</p>
				<%} %>
			</li>
			<li><a href="/Vnplace/content-editor/logout.jsp" class="logout">Đăng xuất</a></li>
		</ul>
		</div>

		<!-- // #end mainNav -->

		<div id="containerHolder">
			<div id="container">
				<div id="sidebar">
					<ul class="sideNav">
						<li><a href="/Vnplace/content-editor/contenteditor.jsp">Trang chủ</a></li>
						<li><a href="/Vnplace/content-editor/manageLocation.jsp">Quản lý địa điểm</a></li>
						<li class="create"><a href="/Vnplace/content-editor/manageCategory.jsp" >Quản lý nhóm địa điểm</a></li>
						<li class="error"><a href="/Vnplace/content-editor/manageerror.jsp" >Quản lý lỗi</a></li>
					</ul>
					<!-- // .sideNav -->
				</div>
				<!-- // #sidebar -->
				<div id="link-home">
					<ul id="link-ul">
						<li><a href="">Trang chủ</a></li>
						<li><img src="image/12.png" width="15px" height="25px" class="home"/></li>
						<li><a href="editLocation.jsp">Chỉnh sửa địa điểm</a></li>
					</ul>	 
				</div>
				
				<%
					int id = Integer.parseInt(request.getParameter("id"));
					LocationDAO localdao = new LocationDAO();
					Location a = localdao.getLocalNew(id);
				%>
				<div id="main">
						
								<div class="title">
									<p class="p-title">Chỉnh sửa địa điểm</p>
								</div>								
								<hr/>
								<h3 style="margin-left: 30px; font-size: 1.3em">Thông tin cơ bản</h3>
								
							<form action="/Vnplace/EditLocation" method="post">
								<hr width="950px"/>
									<div id="label-name">
										<label>Tên địa điểm <span>(*)</span>:</label><br/>
										<input type="text" name="localname" id="local-name" size="35" 
												required="required" value="<%=a.getLocationName()%>"/>
									</div>
									<b class="map">Chọn vị trí của địa điểm trên bản đồ</b>
									<small><i>Nhập địa chỉ trước hệ thống sẽ giúp bạn tìm vị trí dễ dàng hơn. <br/>
											  Bạn có thể bỏ qua nếu bạn không thể xác định vị trí chính xác.</i>
									</small>
									<div id="label-category">
										<label>Nhóm địa điểm <span>(*)</span>:</label><br/>
										<select id="category" name="category">
											<option selected="selected">------- Chọn -------</option>
										<%
											List<Category> cate = new ArrayList();
											CategoryDAO catedao = new CategoryDAO();
											cate = catedao.listAllCategory();
											for(Category c: cate){
										%>
											<option value="<%=c.getIdcate()%>"><%=c.getCategory() %></option>
										<%} %>
										</select>
									</div>
									
									<div id="map-canvas"></div>
									<div id="label-address">
									<label>Tỉnh/thành phố <span>(*)</span>:</label> <br/>
									<select id="province" name="province" >
										<option value="" selected="selected">------- Chọn -------</option>
										<option value="1">An Giang</option>
										<option value="2">B&#224; Rịa Vũng T&#224;u</option>
										<option value="3">Bắc Giang</option>
										<option value="4">Bắc Kạn</option>
										<option value="5">Bạc Li&#234;u</option>
										<option value="6">Bắc Ninh</option>
										<option value="7">Bến Tre</option>
										<option value="8">B&#236;nh Định</option>
										<option value="9">B&#236;nh Dương</option>
										<option value="10">B&#236;nh Phước</option>
										<option value="11">B&#236;nh Thuận</option>
										<option value="12">C&#224; Mau</option>
										<option value="13">Cần Thơ</option>
										<option value="14">Cao Bằng</option>
										<option value="15">Đ&#224; Nẵng</option>
										<option value="16">Đắk Lắk</option>
										<option value="17">Đăk N&#244;ng</option>
										<option value="18">Điện Bi&#234;n</option>
										<option value="19">Đồng Nai</option>
										<option value="20">Đồng Th&#225;p</option>
										<option value="21">Gia Lai</option>
										<option value="22">H&#224; Giang</option>
										<option value="23">H&#224; Nam</option>
										<option value="24">H&#224; Nội</option>
										<option value="25">H&#224; Tĩnh</option>
										<option value="26">Hải Dương</option>
										<option value="27">Hải Ph&#242;ng</option>
										<option value="28">Hậu Giang</option>
										<option value="29">H&#242;a B&#236;nh</option>
										<option value="30">Hưng Y&#234;n</option>
										<option value="31">Kh&#225;nh H&#242;a</option>
										<option value="32">Ki&#234;n Giang</option>
										<option value="33">Kon Tum</option>
										<option value="34">Lai Ch&#226;u</option>
										<option value="35">L&#226;m Đồng</option>
										<option value="36">Lạng Sơn</option>
										<option value="37">L&#224;o Cai</option>
										<option value="38">Long An</option>
										<option value="39">Nam Định</option>
										<option value="40">Nghệ An</option>
										<option value="41">Ninh B&#236;nh</option>
										<option value="42">Ninh Thuận</option>
										<option value="43">Ph&#250; Thọ</option>
										<option value="44">Ph&#250; Y&#234;n</option>
										<option value="45">Quảng B&#236;nh</option>
										<option value="46">Quảng Nam</option>
										<option value="47">Quảng Ng&#227;i</option>
										<option value="48">Quảng Ninh</option>
										<option value="49">Quảng Trị</option>
										<option value="50">S&#243;c Trăng</option>
										<option value="51">Sơn La</option>
										<option value="52">T&#226;y Ninh</option>
										<option value="53">Th&#225;i B&#236;nh</option>
										<option value="54">Th&#225;i Nguy&#234;n</option>
										<option value="55">Thanh H&#243;a</option>
										<option value="56">Th&#224;nh Phố Hồ Ch&#237; Minh</option>
										<option value="57">Thừa Thi&#234;n Huế</option>
										<option value="58">Tiền Giang</option>
										<option value="59">Tr&#224; Vinh</option>
										<option value="60">Tuy&#234;n Quang</option>
										<option value="61">Vĩnh Long</option>
										<option value="62">Vĩnh Ph&#250;c</option>
										<option value="63">Y&#234;n B&#225;i</option>
									</select> <br />
									
<!-- 									<label>Quận/huyện <span>(*)</span>:</label> <br/> -->
<!-- 									<select id="districts" name="district"> -->
<%-- 									<% --%>
										
<!-- // 										String province = request.getParameter("province"); -->
<!-- // 									if(province!=null){ -->
<!-- // 										List<District> list = new ArrayList<District>(); -->
<!-- // 										CategoryDAO ctedao = new CategoryDAO(); -->
<!-- // 										list = ctedao.listDistrict(Integer.parseInt(province)); -->
<!-- // 										for(District d: list){ -->
<%-- 									%> --%>
<%-- 										<option value="<%=d.getDistrict()%>"><%=d.getDistrict() %></option> --%>
										
<%-- 									<%}  --%>
<%-- 									}%> --%>
<!-- 									</select> -->
									<br/>
									 <label>Địa điểm chi tiết<span>(*)</span>:</label><br/>
										<input type="text" id="district" name="addresslocal" value="<%=a.getAddressDetail()%>"
											 placeholder="Nhập đường(xã), quận(huyện)..." size="45" required/><br/>    
									</div>
									
									<div id="label-phone">
										<label>Số điện thoại:</label><br/>
										<input type="text" name="phone" id="txtPhone" value="<%=a.getPhone()%>"/>
										<span id="spnPhoneStatus"></span>
									</div>
									
									<div id="label-web">
										<label>Website:</label><br/>
										<input type="text" name="website" id="txtWebsite" size="35" value="<%=a.getWebsite()%>"/>
										<span id="spnWebStatus"></span>
									</div>
									
									<input type="hidden" value="<%=id%>" name="id"/>

									<div id="descript">
										<label>Mô tả chi tiết <span>(*)</span>:</label><br />
										<textarea rows="20" cols="100" id="description" name="descript"  required="required"><%=a.getDescript() %></textarea>
									</div>
									<div id="label-image">
										<label>Hình ảnh:</label><br/>
										<input type="text" id="image" name="image" placeholder="Vui lòng nhập link ảnh" size="50"/>
									</div>
									<p style="margin-top: 10px; margin-left: 15px; margin-bottom: 10px;">Những phần có đánh dấu (*) là những phần bắt buộc phải nhập</p>
<!-- 									<br/> -->
									<div id="button">
										<ul id="btn-ul">
											<li><input type="submit" value="Cập nhật" class="btn-create"/></li>
											<li><input type="button" value="Hủy" class="btn-cancel" onclick="window.location='/Vnplace/content-editor/viewLocation.jsp?id=<%=id%>'"/></li>
										</ul>
									</div>
									<br/><br/><br/><hr/>
									 <div style="margin-top:5px">
			                            <script>
			                                google_ad_client = "ca-pub-1704544291315733";
			                                google_ad_slot = "9722485402";
			                                google_override_format = true;
			                                google_ad_width = 997;
			                                google_ad_height = 90;
			                            </script>
			                            <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
			                        </div>
						</form>
<!-- 							end form -->
				</div>
				<!-- // #main -->
				<div class="clear"></div>
			</div>
			<!-- // #container -->
		</div>
		<!-- // #containerHolder -->
		<div id="footer" class="footer">
			<p class="copyright">©Copyright 2014 Vnplace.vn</p>
		</div>
	</div>

	<!-- // #wrapper -->
</body>
</html>
